package servlet;

import java.awt.Color;
import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JFileChooser;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

/**
 * Servlet implementation class testPrint
 */
@WebServlet("/testPrint")
public class testPrint extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("application/pdf");
		Document myDocument = new Document(PageSize.A4, 36, 36, 72, 72);

		try {
			// Writes particulars into PDF file
			PdfWriter.getInstance(myDocument, response.getOutputStream());

			myDocument.setMarginMirroring(true);

			myDocument.open();
			Font fontbold = new Font();
			fontbold.setStyle(Font.BOLD);

			// Terms of reference
			myDocument.add(new Paragraph("TERMS OF REFERENCE", fontbold));

			myDocument
					.add(new Paragraph(
							"______________________________________________________________________________")); // Divider
																												// line

			myDocument.add(new Paragraph("     "));

			// Committee Title
			Chunk comm_title = new Chunk("Committee Title", fontbold);
			comm_title.setUnderline(1f, -2f);
			myDocument.add(comm_title);

			myDocument.add(new Paragraph("     "));

			// Role and staff
			myDocument.add(new Paragraph("Rolename : Staff"));

			myDocument.add(new Paragraph("     "));
			myDocument.add(new Paragraph("     "));

			// Purpose
			Chunk Purpose = new Chunk("Purpose", fontbold);
			myDocument.add(Purpose);

			myDocument.add(new Paragraph("     "));
			myDocument.add(new Paragraph("Purpose content"));

			myDocument.add(new Paragraph("     "));
			myDocument.add(new Paragraph("     "));

			// Roles & Responsibilities
			myDocument.add(new Paragraph("Roles & Responsibilities", fontbold));

			myDocument.add(new Paragraph("     "));
			myDocument.add(new Paragraph("R&R content"));

			myDocument.add(new Paragraph("     "));
			myDocument.add(new Paragraph("     "));

			// frequency of meeting
			myDocument.add(new Paragraph("Frequency of Meeting : Once a year",
					fontbold));
			myDocument.add(new Paragraph("     "));
			myDocument.add(new Paragraph("     "));

			myDocument.add(new Paragraph(
					"Approved by:  ___________________________________"));

			myDocument
					.add(new Paragraph(
							"                      Director, School Of Information Technology"));

			myDocument.add(new Paragraph("     "));

			myDocument.add(new Paragraph("Effective Date: "));

			myDocument.add(new Paragraph("     "));

			Font f = new Font();
			f.setColor(BaseColor.BLUE);
			f.setStyle(Font.ITALIC);
			myDocument
					.add(new Paragraph(
							"This is a computer generated copy, no signature is required.",
							f));

		} catch (DocumentException de) {
			System.err.println(de.getMessage());
		} catch (IOException ioe) {
			System.err.println(ioe.getMessage());
		}

		myDocument.close();

		// End of Appointment letter codes
	}

}
